package com.newshub.ai.core.factory;

import com.newshub.ai.core.client.impl.DeepSeekClient;
import com.newshub.ai.core.client.LLMClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * LLM客户端工厂
 * 根据配置动态创建不同类型的LLM客户端
 */
@Slf4j
@Component
public class LLMClientFactory {

    @Autowired
    private DeepSeekClient deepSeekClient;

    /**
     * 创建LLM客户端
     */
    public LLMClient createClient() {
        log.info("创建LLM客户端，默认模型: deepseek");
        return createClient("deepseek");
    }

    /**
     * 创建指定类型的LLM客户端
     */
    public LLMClient createClient(String modelType) {
        log.info("创建指定类型的LLM客户端，类型: {}", modelType);

        switch (modelType.toLowerCase()) {
            case "deepseek":
                return deepSeekClient;
            case "openai":
                // TODO: 实现OpenAI客户端
                log.warn("OpenAI客户端暂未实现，使用模拟客户端");
                return createMockClient("OpenAI");
            case "qwen":
                // TODO: 实现通义千问客户端
                log.warn("通义千问客户端暂未实现，使用模拟客户端");
                return createMockClient("通义千问");
            default:
                log.warn("不支持的AI模型类型: {}，使用模拟客户端", modelType);
                return createMockClient(modelType);
        }
    }

    /**
     * 创建模拟客户端（临时使用）
     */
    private LLMClient createMockClient(String type) {
        return new LLMClient() {
            @Override
            public com.newshub.ai.model.dto.ChatResponse chat(com.newshub.ai.model.dto.ChatRequest request) {
                return com.newshub.ai.model.dto.ChatResponse.success(
                    "这是" + type + "的模拟回复。实际功能正在开发中...", 
                    type
                );
            }

            @Override
            public boolean isAvailable() {
                return true;
            }

            @Override
            public String getClientType() {
                return type;
            }

            @Override
            public String getModelInfo() {
                return type + " (Mock)";
            }
        };
    }
}

